﻿// Copyright richyp 2009
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Text;

namespace Richyp.Bodger.Parser {
    public class ParserFactory {
        private static ParserFactory instance = null;
        public static ParserFactory Instance {
            get {
                if (instance == null) {
                    instance = new ParserFactory();
                }
                return instance;
            }
        }

        public BaseParser CreateParser(Type type) {
            try {
                Type t = type.GetInterface("BaseParser");
                if (t == null) {
                    throw new Exception();
                }
            } catch {
                throw new Exception("Not a valid parser type: " + type);
            }

            return (BaseParser)Activator.CreateInstance(type);
        }
    }
}
